<?php
namespace app\model\auth;

use think\Model;
use Firebase\JWT\JWT;

/*
 * 管理员模型.
 *
 * @property integer $id
 */
class Admin extends Model
{
    protected $table = 'auth_admin';      // 表名

    /*
     * @inheritdoc
     */
    protected $field = [
        'role_id',
        'name',
        'mobile',
        'password',
        'avatar',
        'status',
        'memo'
    ];
    // 查询范围
    public function scopeUser($query)
    {
        $query->where('id', request()->uid);
    }
    public function role(){
        return $this->belongsTo(Role::class)->bind(['role_name' => 'name']);
    }
    public function searchRoleIdAttr($query, $value, $data)
    {
        $value > 0 && $query->where('role_id', $value);
    }
    public function searchStatusAttr($query, $value, $data)
    {
        $value > 0 && $query->where('status', $value);
    }
    public function searchNameAttr($query, $value, $data)
    {
        !empty($value) && $query->where('name|mobile', 'like', '&' . $value . '&');
    }
}
